// var checkName = function(){
//     //声名了全局变量
// }
// //等价于 
// function checkEmail(){

// }

//通过点点方式来使用对象的方法
//way1
var CheckObject1 = {
    checkName : function(){

    },
    checkEmail :function(){
        
    }
}
CheckObject1.checkName()
//way2
var CheckObject2 = function(){}
CheckObject2.checkName = function(){

},
CheckObject2.checkEmail = function(){
        
}
var t1 = CheckObject2()
console.log(t1)
var CheckObject3 = function(){
    return {
        checkName : function(){

        },
        checkEmail :function(){
            
        }
    }
}
var t2 = CheckObject3 ()
console.log(t2)


//利用类
var CheckObject4 = function(){
    this.checkName = function () {}
    this.checkEmail = function () {}
}
var t3 = new CheckObject4()
t3.checkEmail()
console.log(t3)
//在函数本身的原生链上添加方法，每次创建新对象的时候，都会通过this(函数本身的原型上去找)
var CheckObject5 = function(){}
CheckObject5.prototype = {
    checkName : function () {},
    checkEmail : function () {}
}
var t4 = new CheckObject5()
console.log(t4)

var CheckObject6 = function(){}
CheckObject6.prototype = {
    checkName : function () {
        console.log('c6checkName')
        return this
    },
    checkEmail : function () {
        console.log('c6checkEmail')
        return this
    }
}
var t5 = new CheckObject6()
console.log('t5-----',t5.checkEmail().checkName())
var CheckObject7 = {
    checkEmail : function (){
        console.log('c7checkName')
        return this
    },
    checkName : function(){
        console.log('c7checkEmail')
        return this
    }
}
console.log(CheckObject7.checkName().checkEmail())


//可以抽象出以下方法
Function.prototype.addMethods =  function (name, fn){
    this[name] = fn
    return this
    //return this 可以返回函数对象，方便链式调用
}
//但是以上的方法污染来原生对象
var method = function (){}

method.prototype.addMethods('CheckName', function(params) {
    
}).addMethods('CheckEmail', function(params) {
    
})

